home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 July / macformat-039.iso / DATABASE / SHARED.DIR / 01029_bsearch script.ls < prev    next >
Encoding:
Text File  |  1996-03-14  |  615 b   |  26 lines

  1. on Bsearch str, txt
  2.   set txt to the number of cast txt
  3.   set start to 1
  4.   set end to the number of lines in field txt
  5.   set middle to (start + end) / 2
  6.   repeat while str <> item 1 of line middle of field txt
  7.     if str = item 1 of line end of field txt then
  8.       return end
  9.     end if
  10.     if start = middle then
  11.       return 0
  12.     end if
  13.     if str < item 1 of line middle of field txt then
  14.       set end to middle
  15.     else
  16.       set start to middle
  17.     end if
  18.     set middle to (start + end) / 2
  19.   end repeat
  20.   if str = item 1 of line middle of field txt then
  21.     return middle
  22.   else
  23.     return 0
  24.   end if
  25. end
  26.